Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Controllers

In order for a user to interact successfully with the objects in a three-dimensional model, it's necessary for the computer to provide some means of manipulating positions along three independent axes. Most existing computer systems support only two-dimensional input devices, such as mouse pointers or graphics tablets. QuickDraw 3D provides a standard interface between applications and devices that allows users to work with any available 3D pointing devices. In addition, the QuickDraw 3D Pointing Device Manager provides routines that you can use to determine what kinds of 3D pointing devices are available and to assign certain of them to specific uses in your application.

A 3D pointing device is any physical device capable of controlling movements or specifying positions in three-dimensional space. QuickDraw 3D represents 3D pointing devices as controller objects (or, more briefly, controllers ). A user can attach more than one 3D pointing device to a computer. Accordingly, QuickDraw 3D can support more than one controller at a time. When several 3D pointing devices are present, they can all contribute to the movement of a single user interface element (such as the position of the selected object), or they can control different elements. For example, a particular 3D pointing device can be dedicated to controlling a view's camera, and another 3D pointing device can drive the position of the selected object.

The position and orientation of a single element in your application's user interface are represented by a tracker object (or, more briefly, a tracker ). For instance, the position and orientation of a selected object are represented by a tracker, as is any other interface element you've assigned to some controller. Each controller can affect only one tracker, but a tracker can be affected by one or more controllers. Figure 2 illustrates a possible arrangement of devices, controllers, and trackers.

Figure 2 A sample configuration of input devices, controllers, and trackers

The controller object associated with a particular 3D pointing device is usually created by a device driver, the software that communicates with the device using whatever low-level protocols are appropriate for the device. The device can be connected to the computer through a serial port, via ADB connections, through an expansion card, or by other means. The device driver receives data from the device and passes it to the associated controller. As already indicated, a controller is associated with exactly one tracker. Changes in the position or orientation of the pointing device thereby result in changes in the position or orientation of the associated tracker.

By default, a controller contributes to the position of the system's cursor. You can, if you wish, reassign a particular controller to control the position or orientation of some other user interface element.

All controllers are capable of controlling positions, and some controllers are capable of controlling orientations as well. Pointing devices contain one or more buttons; the associated controller must be capable of reading button states (up or down) from the pointing device and reporting those states to the tracker. Currently, QuickDraw 3D supports up to 32 buttons on a 3D pointing device. More generally, a pointing device may support additional input and output modes as well. For example, it's possible to construct a 3D pointing device that contains a number of dials and alphanumeric displays labeling those dials. The device's controller must then be able to communicate information about dials and labels between the device and an application using that device.

Any piece of information, beyond the standard position, orientation, and buttons, that the user sends to the application by means of an input device is called a controller value. Any piece of information sent from the application to the input device is called a controller channel. A dial position, for example, is a controller value, whereas an alphanumeric label generated by the application is a controller channel.

In general, your application does not need to communicate with controllers directly. As already indicated, controllers are almost always created by their associated device drivers, which read data from the devices and pass it to the associated controller. Moreover, a controller is by default connected to the cursor. Your application needs to access a controller only to assign it to some interface element other than the cursor or to read controller data other than position, orientation, and button states. To get information about other controller values, for instance, you need to call routines that query the controller directly.

QuickDraw 3D maintains a list of all the controllers that are available on a computer. A controller is identified by its signature, which is a string that uniquely identifies the manufacturer and model of the controller. You can search for a controller by signature by calling QuickDraw 3D Pointing Device Manager routines. Once a controller is added to the list of available controllers, it cannot be removed from it, but it can be made inactive. If for some reason a device becomes unavailable, the device driver should mark the controller as inactive. The device might later become available, in which case the driver can reactivate the controller. You should always check that a controller is active before directly accessing a controller from the list of controllers.

Because controllers may be shared by multiple applications, you cannot dispose of a controller. Instead, you can decommission the controller by calling Q3Controller_Decommission . Decommissioning a controller makes it inoperative for any application.

Controllers are referenced by the TQ3ControllerRef type:

typedef void *TQ3ControllerRef;

© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |